package com.ubb.damate.webservice;

import java.util.Date;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import com.ubb.damate.model.File;
import com.ubb.damate.model.FilePK;
import com.ubb.damate.model.Workspace;
import com.ubb.damate.service.FileServiceLocal;
import com.ubb.damate.service.WorkspaceServiceLocal;

/** Session Bean implementation class FileWebService */
@Stateless
@WebService()
public class FileWebService {
	@EJB(beanName = "FileService")
	private FileServiceLocal		fileService;
	@EJB(beanName = "WorkspaceService")
	private WorkspaceServiceLocal	workspaceService;

	@WebMethod(action = "createOrUpdateFile", operationName = "createOrUpdateFile")
	public boolean createOrUpdateFile(@WebParam(name = "username") String username, @WebParam(name = "workspacePath") String workspacePath, @WebParam(name = "projectName") String projectName,
			@WebParam(name = "fileName") String fileName) {
		Workspace workspace = workspaceService.find(username, workspacePath);

		FilePK filePK = new FilePK();
		filePK.setFileName(fileName);
		filePK.setProjectName(projectName);
		filePK.setWorkspaceId(workspace.getWorkspaceId());

		File file = new File();
		file.setCreationDate(new Date());
		file.setId(filePK);

		fileService.createOrUpdate(file);

		return true;
	}
}
